Change the default value of GtkWidget:can-focus
authorMatthias Clasen <mclasen@redhat.com>
Wed, 8 Apr 2020 11:40:48 +0000 (07:40 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Thu, 9 Apr 2020 21:50:29 +0000 (17:50 -0400)
Make widgets can-focus by default, and change the semantics
of can-focus to be recursive . If it is set to FALSE, focus
can not enter the widget or its descendents at all anymore.

This commit temporarily breaks focus behavior of widgets
that did not expect to receive focus.

demos/gtk-demo/fontplane.c
gtk/gtkbutton.c
gtk/gtkcolorplane.c
gtk/gtkexpander.c
gtk/gtkiconview.c
gtk/gtklistbox.c
gtk/gtknotebook.c
gtk/gtktreeview.c
gtk/gtkwidget.c

index 1f7e074adbcce6c2480bfe1c231b6c7ea8657a6e..0a7aae63396ae5b77a9a0176a9216d981c493762 100644 (file)
@@ -189,8 +189,6 @@ gtk_font_plane_init (GtkFontPlane *plane)
 {
   GtkGesture *gesture;
 
-  gtk_widget_set_can_focus (GTK_WIDGET (plane), TRUE);
-
   gesture = gtk_gesture_drag_new ();
   g_signal_connect (gesture, "drag-begin",
                    G_CALLBACK (plane_drag_gesture_begin), plane);
index d633c77fe6a217da534be8157f557f528697804e..52165f83178eefa48081704b3cf48f83e98de214 100644 (file)
@@ -408,7 +408,6 @@ gtk_button_init (GtkButton *button)
   GtkButtonPrivate *priv = gtk_button_get_instance_private (button);
   GtkEventController *key_controller;
 
-  gtk_widget_set_can_focus (GTK_WIDGET (button), TRUE);
   gtk_widget_set_receives_default (GTK_WIDGET (button), TRUE);
 
   priv->in_button = FALSE;
index 2c4ae692f219bee56ca9c3dc6577495705c1714c..5b88ea3ba9f470a6797f404ab9c0c21064cd13cd 100644 (file)
@@ -407,8 +407,6 @@ gtk_color_plane_init (GtkColorPlane *plane)
 
   plane->priv = gtk_color_plane_get_instance_private (plane);
 
-  gtk_widget_set_can_focus (GTK_WIDGET (plane), TRUE);
-
   atk_obj = gtk_widget_get_accessible (GTK_WIDGET (plane));
   if (GTK_IS_ACCESSIBLE (atk_obj))
     {
index dbe31e68e0d4b71b4d0fadf2758b54348d675f8e..91f73aa6543b90d498b17ae91e9437db52df3202 100644 (file)
@@ -385,8 +385,6 @@ gtk_expander_init (GtkExpander *expander)
   GtkGesture *gesture;
   GtkEventController *controller;
 
-  gtk_widget_set_can_focus (GTK_WIDGET (expander), TRUE);
-
   priv->label_widget = NULL;
   priv->child = NULL;
 
index 275b59867567a210f9d4ae221ceebc6c55cb9bc5..508a016c19cdee3b4248545fbec4c8ad6655f2bb 100644 (file)
@@ -943,7 +943,6 @@ gtk_icon_view_init (GtkIconView *icon_view)
   icon_view->priv->mouse_x = -1;
   icon_view->priv->mouse_y = -1;
 
-  gtk_widget_set_can_focus (GTK_WIDGET (icon_view), TRUE);
   gtk_widget_set_overflow (GTK_WIDGET (icon_view), GTK_OVERFLOW_HIDDEN);
 
   icon_view->priv->item_orientation = GTK_ORIENTATION_VERTICAL;
index bae24231cd63087309e9f6dbd9fbc0e5c6b036ee..f2cf390cde85d67cddb5eb04ac0bda0165288a5d 100644 (file)
@@ -3430,8 +3430,6 @@ gtk_list_box_row_class_init (GtkListBoxRowClass *klass)
 static void
 gtk_list_box_row_init (GtkListBoxRow *row)
 {
-  gtk_widget_set_can_focus (GTK_WIDGET (row), TRUE);
-
   ROW_PRIV (row)->activatable = TRUE;
   ROW_PRIV (row)->selectable = TRUE;
 
index 9b78beffa84aa14d9bd503d6a4e37e5244bbb832..96b1f598e9f2363454b7e2d7975e0df33bc9f189 100644 (file)
@@ -1387,8 +1387,6 @@ gtk_notebook_init (GtkNotebook *notebook)
   GtkLayoutManager *layout;
   GtkDropTarget *dest;
 
-  gtk_widget_set_can_focus (GTK_WIDGET (notebook), TRUE);
-
   notebook->cur_page = NULL;
   notebook->children = NULL;
   notebook->first_tab = NULL;
@@ -6087,8 +6085,6 @@ gtk_notebook_set_show_tabs (GtkNotebook *notebook,
 
   if (!show_tabs)
     {
-      gtk_widget_set_can_focus (GTK_WIDGET (notebook), FALSE);
-
       while (children)
         {
           page = children->data;
@@ -6106,7 +6102,6 @@ gtk_notebook_set_show_tabs (GtkNotebook *notebook,
     }
   else
     {
-      gtk_widget_set_can_focus (GTK_WIDGET (notebook), TRUE);
       gtk_notebook_update_labels (notebook);
       gtk_widget_show (notebook->header_widget);
     }
index 3580ab8f8dec1bec33be08cd4d5ac8c8e9b518b2..6d68907a5ad08c33f5241ab6fffb1b48e63427c5 100644 (file)
@@ -1707,7 +1707,6 @@ gtk_tree_view_init (GtkTreeView *tree_view)
   GtkEventController **controllers;
   guint n_controllers, i;
 
-  gtk_widget_set_can_focus (GTK_WIDGET (tree_view), TRUE);
   gtk_widget_set_overflow (GTK_WIDGET (tree_view), GTK_OVERFLOW_HIDDEN);
 
   tree_view->show_expanders = TRUE;
index 38233c1359c9f16e07340f242f6b3c183e54d751..706fc5f0bec440946a6227f672148b997de7b396 100644 (file)
@@ -978,7 +978,7 @@ gtk_widget_class_init (GtkWidgetClass *klass)
       g_param_spec_boolean ("can-focus",
                             P_("Can focus"),
                             P_("Whether the widget can accept the input focus"),
-                            FALSE,
+                            TRUE,
                             GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
 
   widget_props[PROP_HAS_FOCUS] =
@@ -2294,6 +2294,7 @@ gtk_widget_init (GTypeInstance *instance, gpointer g_class)
 #ifdef G_ENABLE_DEBUG
   priv->highlight_resize = FALSE;
 #endif
+  priv->can_focus = TRUE;
   priv->can_target = TRUE;
 
   switch (_gtk_widget_get_direction (widget))
@@ -6681,7 +6682,8 @@ gtk_widget_child_focus (GtkWidget       *widget,
   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
 
   if (!_gtk_widget_get_visible (widget) ||
-      !gtk_widget_is_sensitive (widget))
+      !gtk_widget_is_sensitive (widget) ||
+      !gtk_widget_get_can_focus (widget))
     return FALSE;
 
   /* Emit ::focus in any case, even if can-focus is FALSE,